//enterprise.js
const util = require('../../../utils/util.js')
//列表数据
import { enterLists} from "../../../utils/data/enterPrise.js";
import config from '../../../config';
import { getmy} from '../../../utils/api/module/task';
Page({
    data: {
        URL: config._URL_,
        imgs: {
            bgTile: "https://ythapi.bjyangshu.com/public/images/bj@2x.png",
            headerImg:"/assets/img/lsheader.png",
            rzImg: "/assets/img/renz@2x.png",
            unRzImg: "/assets/img/renz2@2x.png",
            toImg: "/assets/img/icon_left.png",
        },
        sysInfo: wx.getSystemInfoSync(),
        enterLists,
        /**
         * 零时数据，需要调用API以后来判断的
         */
        isLogin: '',
        isRz: true,
        statusBarHeight: 0
    },

    onLoad: function () {
        let data = getApp().statusBarHeight;
        this.setData({
            statusBarHeight: Number(data.statusBarHeight)
        })
        this.setMenuLocal();
    },
    onShow() {
        this.getMyinfo();
    },
    setMenuLocal(){
        //获取到胶囊的位置信息
        let menu= wx.getMenuButtonBoundingClientRect();
    },
    /**
     * 点击每个列表项，跳转到相应的页面
     * @param e 参数
     */
    clickItem(e){
        let data = e.currentTarget.dataset;
        if(data.index == 0 && data.idx <= 2) {
            this.bindList(data.idx);
            return false;
        };
        if(data.path != null){
            if (data.index == 1 && data.idx <= 2) {
                let userData = wx.getStorageSync('userInfoData')
                if(data.index == 1 && data.idx != 2) {
                    if (userData.data.certstatus != 3) {
                        this.bindList();
                     }else{
                         wx.navigateTo({
                             url: data.path
                         });
                     };
                }else{
                    if(data.idx == 2 && data.index == 1)  wx.navigateTo({ url: data.path });
                }
                
            }else{
                wx.navigateTo({
                    url: data.path
                });
            };
        }else{
            wx.showModal({
                content:'确认退出登录',
                success(res){
                    if (res.confirm) {
                        wx.removeStorageSync('isLogin');
                        wx.removeStorageSync('userInfo');
                        wx.removeStorageSync('session_id');
                        wx.removeStorageSync('userInfoData');
                        wx.removeStorageSync('loginTimer');
                        wx.clearStorageSync();
                        wx.switchTab({url: '/pages/index/index'})
                    };
                }
            });
        };
    },
    getMyinfo(){
        let data1 = wx.getStorageSync('userInfo')
        if(!data1) {
            this.setData({
                isLogin: false
            })
            return false;
        };
        getmy({
            mid: wx.getStorageSync('userInfo').mid,
        },{
            Cookie: 'SESSION_='+wx.getStorageSync('session_id'),
        }).then(res => {
            wx.setStorageSync("userInfoData", res.data)
            wx.setStorageSync('userInfo', res.data.data);
            wx.setStorageSync('isLogin', true);
            this.setData({
                userinfo: wx.getStorageSync('userInfo'),
                isLogin: wx.getStorageSync('isLogin'),
            })

        })
    },
    // 热门活动
    bindList: function(index) {
        let userData = wx.getStorageSync('userInfoData1'),
            url = '/pages/enterprise/authentication/index',
            title = '需认证通过才能使用该功能',
            btnContent = '重新认证',
            url1 = '/pages/posthome/posthome';
            if(index == 1) url1 = '/views/minePages/partyManage/partyManage';
            if(index == 2) url1 = '/views/minePages/orderList/orderList';
        if(userData.data && userData.data.certstatus == 3) {
            if(!userData.userId36) {
                wx.showModal({
                    title: '提示',
                    content: '登录异常，请重新登录！',
                    cancelText: '取消登录',
                    cancelColor: '#999999',
                    confirmText: '重新登录',
                    confirmColor: '#3b99f5',
                    success: res => {
                    //   this.data.theRedEnvelopeSuper = false;
                      if (res.confirm) {
                        wx.navigateTo({
                            url: '/pages/loginAndRegister/login/index'
                        })
                      }
                    }
                });
                return false;
            }
            wx.navigateToMiniProgram({
                appId: 'wx6f6831e5b83b7535',//互动吧小程序appid
                path: url1,//跳转地址
                extraData:{//用户信息参数，根据自己代码自行赋值
                    "userId36": userData.userId36,
                    "userSecret":  userData.userSecret,
                    "userSign":  userData.userSign
                    },
                envVersion: 'release', // 线上
            });
            return false;
        };
        if(!userData.data || !userData.data.certstatus && userData.data.certstatus != 0) {
            url = '/pages/loginAndRegister/login/index';
            title = '必须登录且认证通过才能使用该功能';
            btnContent = '去登录'
        };
        if(userData.data && userData.data.certstatus == 0) {
            url = '/pages/enterprise/authentication/index';
            title = '需认证通过才能使用该功能';
            btnContent = "去认证";
        };
        if(userData.data && userData.data.certstatus == 1) {
            url = '/pages/enterprise/authentication/index';
            title = '需认证通过才能使用该功能';
            btnContent = "去查看";
        };
        wx.showModal({
            title: '提示',
            content: title,
            cancelText: '取消',
            cancelColor: '#999999',
            confirmText: btnContent,
            confirmColor: '#3b99f5',
            success: res => {
              this.data.theRedEnvelopeSuper = false;
              if (res.confirm) {
               wx.navigateTo({
                 url: url
               })
              }
            }
        });
    },
})